package com.zuo.mall.controller;

import com.zuo.mall.common.api.CommonResult;
import com.zuo.mall.entity.PmsSkuStock;
import com.zuo.mall.service.PmsSkuStockService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sku")
public class PmsSkuStockController {
    @Autowired
    private PmsSkuStockService skuStockService;

    @ApiOperation("根据商品ID及sku编码模糊搜索sku库存")
    @GetMapping(value = "/{pid}")
    public CommonResult<List<PmsSkuStock>> getList(@PathVariable Long pid, @RequestParam(value = "keyword", required = false) String keyword) {
        List<PmsSkuStock> skuStockList = skuStockService.getList(pid, keyword);
        return CommonResult.success(skuStockList);
    }

    @PostMapping("update/{pid}")
    public CommonResult updateBatch(@PathVariable("pid") Long pid, @RequestBody List<PmsSkuStock> skuStockList) {
        int count = skuStockService.updateBatchByProductId(pid, skuStockList);
        if(count>0){
            return CommonResult.success(count);
        }else{
            return CommonResult.failed();
        }
    }
}
